package com.heyqing.topic.ReverseList_0206;

import java.util.Objects;

/**
 * ClassName:ReverseList
 * Package:com.heyqing.topic.ReverseList_0206
 * Description:
 *
 * @Date:2024/9/22
 * @Author:Heyqing
 */
public class ReverseList {
    public ListNode reverseList(ListNode head) {
        return achieveFunc(head, null);
    }

    private ListNode achieveFunc(ListNode head, ListNode lastNode) {
        if (Objects.isNull(head)) return lastNode;
        ListNode currentNode = new ListNode(head.val, lastNode);
        System.out.println(currentNode.val);
        return achieveFunc(head.next, currentNode);
    }
}
